<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>删除用户页面</title>
    <script src="js/axios.min.js"></script>
    <script src="js/jquery-1.11.3.min.js"></script>
    <script src="js/vue.js"></script>
    <script src="layui/layui.js"></script>
    <script src="js/vue-router.js"></script>
    <link rel="stylesheet" href="layui/css/layui.css"/>
    <link rel="stylesheet" href="css/goods.css"/>
    <link rel="stylesheet" href="/static/build/layui.css" media="all">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
</head>
<body>
<blockquote class="layui-elem-quote">选择想要删除的用户</blockquote>

<div class="demoTable">
    搜索ID：
    <div class="layui-inline">
        <input class="layui-input" name="id" id="id" id="demoReload" autocomplete="off">
    </div>
    <button class="layui-btn" data-type="reload">搜索</button>
</div>


<table class="layui-hide" id="test" lay-filter="test"></table>



<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>


<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

<script>
    layui.use('table', function(){
        var table = layui.table;

        table.render({
            elem: '#test'
            ,id:'tableOne'
            ,url:'http://47.94.138.204:7790/example/userroot'
            ,where: {
                id:''
            }
            ,title: '用户数据表'
            ,cols: [[
                {field:'id', title:'用户id', width:100, fixed: 'left', unresize: true, sort: true}
                ,{field:'username', title:'用户名', width:100, fixed: 'left', unresize: true, sort: true}
                ,{field:'password', title:'密码', width:190, edit: 'text'}
                ,{field:'gender', title:'性别', width:100, edit: 'text'}
                ,{field:'identity', title:'身份', width:100, edit: 'text', sort: true}
                ,{field:'tele', title:'手机号', width:100, edit: 'text', sort: true}
                ,{field:'address', title:'地址', width:100, edit: 'text', sort: true}
                ,{field:'age', title:'年龄', width:100, edit: 'text', sort: true}
                ,{field:'root', title:'权限', width:100, edit: 'text', sort: true}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
            ]]
            ,page: true
        });
        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            //console.log(obj)
            if(obj.event === 'del'){
                layer.confirm('删除当前用户？', function(index){
                    obj.del();
                    $.ajax({
                        type:"GET",
                        url:"http://47.94.138.204:7790/example/delete?id=" + obj.data.id ,
                        success:function(data){
                            alert("http://127.0.0.1:7747/example/delete?id=" + obj.data.id )
                        },
                    });
                    layer.close(index);
                });
            }
        });
        var $ = layui.$, active = {
            reload: function(){
                var demoReload = $('#demoReload');

                //执行重载
                table.reload('tableOne', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        id:document.getElementById('id').value
                    }
                }, 'data');
            }
        };

        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>

</body>
</html>
</body>
</html>